﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.UI;
using PlatypusPlanner.Components.BLL;
using System.Linq;
using PlatypusPlanner.Components.Database;
using PlatypusPlanner.Components.Utilities;

namespace PlatypusPlanner.ViewControls
{
    public class BasePage : Page
    {

        #region query string properties

        public string QueryTaskName
        {
            get
            {
                return QueryStringUtility.Instance().GetQueryStringValue("name");
            }
        }

        public int QueryMessageId
        {
            get
            {
                return QueryStringUtility.Instance().GetQueryStringValueInt32("message");
            }
        }
        public long QueryCommitteeId
        {
            get
            {
                return QueryStringUtility.Instance().GetQueryStringValueInt64("committee");
            }
        }
        public long QueryAccountUserId
        {
            get
            {
                return QueryStringUtility.Instance().GetQueryStringValueInt64("accountuser");
            }
        }
        public long QueryEventId
        {
            get
            {
                return QueryStringUtility.Instance().GetQueryStringValueInt64("event");
            }
        }
        public long QueryEventScheduleId
        {
            get
            {
                return QueryStringUtility.Instance().GetQueryStringValueInt64("schedule");
            }
        }
        public long QueryBMMessageId
        {
            get
            {
                return QueryStringUtility.Instance().GetQueryStringValueInt64("bmmessage");
            }
        }
        public long QueryFolderId
        {
            get
            {
                return QueryStringUtility.Instance().GetQueryStringValueInt64("folder");
            }
        }
        public long QueryTagId
        {
            get
            {
                return QueryStringUtility.Instance().GetQueryStringValueInt64("tag");
            }
        }
        public long QueryTaskListId
        {
            get
            {
                return QueryStringUtility.Instance().GetQueryStringValueInt64("tasklist");
            }
        }
        public int QueryTaskId  //this was long, changed to int for database needs (make db in future longint instead of int)
        {
            get
            {
                return QueryStringUtility.Instance().GetQueryStringValueInt32("task");
            }
        }
        public long QueryBillingTypeId
        {
            get
            {
                return QueryStringUtility.Instance().GetQueryStringValueInt64("billing");
            }
        }
        public long QueryAccessGroupId
        {
            get
            {
                return QueryStringUtility.Instance().GetQueryStringValueInt64("group");
            }
        }


        #endregion

        #region public properties


        private PlatypusPlanner.Components.Model.Message _currentMessage = null;
        public PlatypusPlanner.Components.Model.Message CurrentMessage
        {
            get
            {
                if (_currentMessage == null && QueryMessageId != 0)
                    _currentMessage = XMLParser.GetMessage(QueryMessageId);

                return _currentMessage;
            }
        }



        private pp_user _currentUser = null;
        public pp_user CurrentUser
        {
            get
            {
                if (_currentUser == null)
                {
                    if (Context.User.Identity.IsAuthenticated)
                        _currentUser = new Users().GetByUserEmail(Context.User.Identity.Name);
                }
                return _currentUser;
            }
        }

        /*private tf_task _currentTask = null;
        public tf_task CurrentTask
        {
            get
            {
                if (_currentTask == null)
                {
                    _currentTask = new Tasks().GetByTaskId(QueryTaskId);
                    //_currentTask = new Tasks().GetByTask();     //not sure what to put in for GetByTask
                }
                return _currentTask;
            }
        }
         * 
         */

        #endregion

        #region load functions






        #endregion

        #region error handling

        //protected override void OnError(EventArgs e)
        //{
        //    try
        //    {
        //        Exception ex = Server.GetLastError();
        //        Server.ClearError();

        //        if (ex != null)
        //        {
        //            if (ex is HttpRequestValidationException)
        //                QueryStringUtility.Instance().RedirectWithMessage(HttpContext.Current.Request.RawUrl, 999);
        //        }
        //    }
        //    catch { }
        //    base.OnError(e);
        //}

        #endregion
    }
}
